#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int cmp1(const void* p1, const void* p2)
{
	if (*(int*)p1 > *(int*)p2)
		return 1;
	else if (*(int*)p1 == *(int*)p2)
		return 0;
	else
		return -1;
}
void Print1(int* p,int len)
{
	for (int i = 0; i < len; i++)
	{
		printf("%d ", *(p + i));
	}
	printf("\n");
}
void test1(void)
{
	int n[] = { 4,3,6,5,2,1,9,7,8 };
	int sz = sizeof(n) / sizeof(n[0]);
	qsort(n, sz, sizeof(n[0]), cmp1);
	Print1(n,sz);
}
int cmp2(const void* p1, const void* p2)
{
	if (*(float*)p1 > *(float*)p2)
		return 1;
	else if (*(float*)p1 == *(float*)p2)
		return 0;
	else
		return -1;
}
void Print2(float* p, int len)
{
	for (int i = 0; i < len; i++)
	{
		printf("%.2f ", *(p + i));
	}
	printf("\n");
}
void test2(void)
{
	float n[] = { 4.0f,3.0f,6.0f,5.0f,2.0f,1.0f,9.0f,7,8.0f };
	int sz = sizeof(n) / sizeof(n[0]);
	qsort(n, sz, sizeof(n[0]), cmp2);
	Print2(n, sz);
}
struct stu 
{
	int age;
	char name[20];
};
int cmp3(const void* p1, const void* p2)
{
	return strcmp(((struct stu *)p1)->name, ((struct stu*)p2)->name);
}

void test3(void)
{
	
	struct stu stuarr[3] = { {30,"zhangsan"},{15,"lisi"} ,{18,"wangwu"} };
	int sz = sizeof(stuarr) / sizeof(stuarr[0]);
	qsort(stuarr, sz, sizeof(stuarr[0]), cmp3);
}

int main()
{
	test1();
	test2();
	test3();
	return 0;
}
